home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / ned100.zip / NEDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-08  |  76KB  |  2,305 lines

  1. { FILE:  nedemo.pas }
  2.  
  3.  
  4.  
  5. program EditDemo;
  6.  
  7.  
  8.  
  9. { -------------------------------------------------------------------- }
  10. {                                                                      }
  11. {                                                                      }
  12. { NEDEMO.PAS is loosly based on the Borland TVEDIT program.            }
  13. { Therefore, as with NEWEDIT, all copyrights apply.  However,          }
  14. { I've freely "included" code from other CIS BPROGA contributers,      }
  15. { and have made every attempt to give credit where it is due.          }
  16. {                                                                      }
  17. { This file contains the driver code for the NEWEDIT unit.  The        }
  18. { driver is NOT necessary to use NEWEDIT.  You can plug NEWEDIT        }
  19. { into your application or Borland's TVEDIT demo if you like.          }
  20. { Please read the NEWEDIT.DOC file for further information on          }
  21. { how to use NEWEDIT with other programs.                              }
  22. {                                                                      }
  23. { You should NOT place anything in here that does not have to do       }
  24. { with menus, the status line, the video screen, or the desktop.       }
  25. {                                                                      }
  26. { NEDEMO.PAS shows various techniques to modify the screen size,       }
  27. { keep the GADGETS heap view under control when switching screen       }
  28. { sizes, load and store the desktop, modifying the status line to      }
  29. { change when certain keys are pressed, and a quick and dirty method   }
  30. { of setting your own palette colors.                                  }
  31. {                                                                      }
  32. { Each of these techniques is clearly marked by a "label."  If you     }
  33. { are interested in a particular technique, search for one of the      }
  34. { labels listed below to see the applicable code.                      }
  35. {                                                                      }
  36. { Label    Description:                                                }
  37. { ------   ------------                                                }
  38. {                                                                      }
  39. { COLORS  - A quick and dirty method to modify the TV palette.         }
  40. {                                                                      }
  41. { DESKTOP - Methods for loading and storing the desktop                }
  42. {           automatically.                                             }
  43. {                                                                      }
  44. { MEMWIN  - How to keep the memory indicator view positioned properly. }
  45. {                                                                      }
  46. { SCRNSZ  - Method for switching between normal and 43/50 lines.       }
  47. {                                                                      }
  48. { STATLN  - Method for modifying the status line.                      }
  49. {                                                                      }
  50. { Al Andersen - 02/29/92.                                              }
  51. {                                                                      }
  52. { -------------------------------------------------------------------- }
  53.  
  54.  
  55. {$F+,X+,S-,D-}
  56. {$M 16384,8192,655360}
  57.  
  58.  
  59.  
  60. { -------------------------------------------------------------------------- }
  61. {                                                                            }
  62. {                        UNITS REQUIRED BY APPLICATION                       }
  63. {                                                                            }
  64. { -------------------------------------------------------------------------- }
  65.  
  66.  
  67. uses
  68.  
  69.   Dos,
  70.   Buffers,
  71.   Objects,
  72.   Drivers,
  73.   Memory,
  74.   Views,
  75.   Menus,
  76.   Dialogs,
  77.   StdDlg,
  78.   MsgBox,
  79.   App,
  80.   HelpFile,
  81.   Gadgets,
  82.   CmdFile,      { Add CmdFile, EditPkg, NewEdit, and EditHelp. }
  83.   EditPkg,
  84.   NewEdit;
  85.  
  86.  
  87.  
  88. { -------------------------------------------------------------------------- }
  89. {                                                                            }
  90. {              GLOBAL OBJECT, VARIABLE, CONSTANT DECLARATIONS                }
  91. {                                                                            }
  92. { -------------------------------------------------------------------------- }
  93.  
  94.  
  95.  
  96.   { ------------------------------------------------ }
  97.   {                                                  }
  98.   { Define object for application called T_EditDemo. }
  99.   { Override and/or add methods to utilize object.   }
  100.   {                                                  }
  101.   { ------------------------------------------------ }
  102.  
  103.  
  104. TYPE
  105.  
  106.   P_EditDemo = ^T_EditDemo;
  107.   T_EditDemo = object (App.TApplication)
  108.  
  109.     { MEMWIN - Start. }
  110.  
  111.     Memory_Indicator : PHeapView;
  112.  
  113.     { MEMWIN - Stop. } { For heap display on satus line. }
  114.  
  115.     constructor Init;
  116.     destructor  Done; virtual;
  117.  
  118.     { DESKTOP - Start. }
  119.  
  120.     procedure   DesktopReadViews (VAR S : TStream);
  121.     procedure   DesktopWriteViews (VAR S : TStream);
  122.  
  123.     { DESKTOP - Stop. } { Methods to read and write the desktop file. }
  124.  
  125.     { COLORS  - Start. }
  126.  
  127.     function    GetPalette : Views.PPalette; virtual;
  128.  
  129.     { COLORS - Stop. } { Method to replace the current palette with our palette. }
  130.  
  131.     procedure   GetEvent (var Event : Drivers.TEvent); virtual;
  132.     procedure   HandleEvent (var Event : Drivers.TEvent); virtual;
  133.     procedure   Idle; virtual;
  134.     procedure   InitMenuBar; virtual;
  135.     procedure   InitStatusLine; virtual;
  136.  
  137.     { MEMWIN  - Start. }
  138.  
  139.     function    Insert_Memory_Indicator : Boolean;
  140.  
  141.     { MEMWIN  - Stop. } { Method to put heap memory view on status line. }
  142.  
  143.     { DESKTOP - Start. }
  144.  
  145.     function    Load_Desktop : Boolean;
  146.  
  147.     { DESKTOP - Stop. } { Method to read desktop off the disk. }
  148.  
  149.     procedure   OutOfMemory; virtual;
  150.  
  151.     { DESKTOP - Start. }
  152.  
  153.     function    Save_Desktop : Boolean;
  154.  
  155.     { DESKTOP - Stop. } { Method to write the desktop to the disk. }
  156.  
  157.     { SCRNSZ  - Start. }
  158.  
  159.     procedure   Toggle_Video_Mode;
  160.  
  161.     { SCRNSZ  - Stop. } { Method to toggle between normal and 43/50 line mode. }
  162.  
  163.   end;
  164.  
  165.  
  166.  
  167.   { --------------------------------------------------------------- }
  168.   {                                                                 }
  169.   { Define object to display what menu items do on the status line. }
  170.   {                                                                 }
  171.   { --------------------------------------------------------------- }
  172.  
  173.  
  174.   { STATLN - Start. }
  175.  
  176.   P_Status_Line_Help  = ^T_Status_Line_Help;
  177.   T_Status_Line_Help  = object (Menus.TStatusLine)
  178.     function Hint (AHelpCtx : Word): String; virtual;
  179.   end;
  180.  
  181.   { STATLN - Stop. } { Object and method to print help on status line. }
  182.  
  183.  
  184.  
  185.   { ----------------------------------------------------- }
  186.   {                                                       }
  187.   { I don't even like the default colors, so I'm creating }
  188.   { a brand new, customized application COLOR palette.    }
  189.   { The monochrome and black-and-white palettes remain    }
  190.   { untouched.                                            }
  191.   {                                                       }
  192.   { ----------------------------------------------------- }
  193.  
  194.  
  195. CONST
  196.  
  197.   { COLORS - Start }
  198.  
  199.   New_Colors =
  200.  
  201.         {0   1   2   3   4   5   6   7   8   9}
  202.  
  203.             #$17#$70#$78#$74#$1F#$47#$1E#$17#$1F +
  204.         #$1A#$17#$4F#$1E#$71#$00#$37#$3F#$3A#$13 +
  205.         #$13#$3E#$21#$00#$70#$7F#$7A#$13#$13#$70 +
  206.         #$1F#$00#$70#$7F#$7A#$17#$1F#$70#$70#$7E +
  207.         #$74#$60#$6B#$6F#$67#$6E#$70#$30#$3F#$3E +
  208.         #$1F#$1B#$1A#$5F#$75#$17#$5F#$30#$2F#$2F +
  209.         #$31#$2F#$00#$00;
  210.  
  211.   { COLORS - Stop } { Custom application palatte. }
  212.  
  213.  
  214.  
  215.   { ------------------------------------------ }
  216.   {                                            }
  217.   { Define any other global constants we need. }
  218.   {                                            }
  219.   { ------------------------------------------ }
  220.  
  221.  
  222. CONST { Command constants. }
  223.  
  224.   { DESKTOP - Start. }
  225.  
  226.   Desktop_Name        : string = 'NEDEMO.DSK';
  227.  
  228.   { DESKTOP - Stop. } { Default name for the desktop disk file. }
  229.  
  230.   { SCRNSZ - Start. }
  231.  
  232.   Current_Screen_Mode : Word = Drivers.ScreenMode;
  233.  
  234.   { SCRNSZ - Stop. } { Desktop variable to keep track of current screen mode. }
  235.  
  236.   Application_Name = 'NEDEMO'; { Application filename required for help. }
  237.  
  238.  
  239.  
  240. { -------------------------------------------------------------------------- }
  241. {                                                                            }
  242. {                           PROCEDURES AND FUNCTIONS                         }
  243. {                                                                            }
  244. { -------------------------------------------------------------------------- }
  245.  
  246.  
  247.  
  248. { STATLN - Start. }
  249.  
  250. procedure Change_Status_Line;
  251.  
  252.  
  253.   { -------------------------------------------------- }
  254.   {                                                    }
  255.   { This procedure changes the state of the status bar }
  256.   { when the user presses Shift, Alt, and Ctrl keys.   }
  257.   {                                                    }
  258.   { Note the following values:                         }
  259.   {                                                    }
  260.   {    $80 - Ins Active                                }
  261.   {    $40 - Caps Lock Active                          }
  262.   {    $20 - Num Lock Active                           }
  263.   {    $10 - Scroll Lock Active                        }
  264.   {    $08 - Alt Depressed                             }
  265.   {    $04 - Ctrl Depressed                            }
  266.   {    $02 - Left Shift Depressed                      }
  267.   {    $01 - Right Shift Depressed                     }
  268.   {                                                    }
  269.   { -------------------------------------------------- }
  270.  
  271.  
  272.   procedure Set_Context;
  273.  
  274.   VAR
  275.  
  276.     KbdWord : Word absolute $0040:$0017;    { Memory location of scancode. }
  277.  
  278.   begin
  279.  
  280.     if KbdWord and $01 <> 0 then
  281.       Desktop^.HelpCtx := CmdFile.hckbShift else              { RightShift }
  282.  
  283.     if KbdWord and $02 <> 0 then
  284.       Desktop^.HelpCtx := CmdFile.hckbShift else              { LeftShift  }
  285.  
  286.     if KbdWord and $04 <> 0 then
  287.       Desktop^.HelpCtx := CmdFile.hckbCtrl else               { Ctrl       }
  288.  
  289.     if KbdWord and $08 <> 0 then
  290.       Desktop^.HelpCtx := CmdFile.hckbAlt else                { Alt        }
  291.  
  292.     Desktop^.HelpCtx := Views.hcNoContext;
  293.  
  294.   end; { Set_Context }
  295.  
  296.  
  297.  
  298. begin { Change_Status_Line }
  299.  
  300.    case Desktop^.HelpCtx of
  301.  
  302.      Views.hcNoContext,
  303.      CmdFile.hckbShift,
  304.      CmdFile.hckbAlt,
  305.      CmdFile.hckbCtrl    : Set_Context;
  306.  
  307.    end;
  308.  
  309. end; { Change_Status_Line }
  310.  
  311. { STATLN - Stop. } { Procedure responsible placing Shift, Alt, Ctrl stats. }
  312.  
  313.  
  314.  
  315. { -------------------------------------------------------------------------- }
  316.  
  317.  
  318.  
  319. function ExecDialog (P : PDialog; Data : Pointer) : Word;
  320.  
  321.  
  322.   { ------------------------------------------------------------- }
  323.   {                                                               }
  324.   { This function handles any dialog box requests you might have. }
  325.   {                                                               }
  326.   { ------------------------------------------------------------- }
  327.  
  328.  
  329. VAR
  330.  
  331.   Result : Word;  { Holds result of last dialog box event. }
  332.  
  333. begin
  334.  
  335.   ExecDialog := Views.cmCancel;
  336.   Result := Views.cmCancel;
  337.  
  338.   P := PDialog (App.Application^.ValidView (P));
  339.  
  340.  
  341.  
  342.   { ------------------------------------------------ }
  343.   {                                                  }
  344.   { If we can't find the dialog box code (programmer }
  345.   { forgot it) tell the user that it is missing.     }
  346.   {                                                  }
  347.   { ------------------------------------------------ }
  348.  
  349.  
  350.   if P = nil then
  351.     begin
  352.       MsgBox.MessageBox (^C'Dialog is missing!', nil,
  353.                          MsgBox.mfError + MsgBox.mfOkButton);
  354.       Exit;
  355.     end;
  356.  
  357.  
  358.  
  359.   { --------------------------------------------------------- }
  360.   {                                                           }
  361.   { If you have a data record for the dialog box, pass it     }
  362.   { to the dialog.  Put the dialog on the desktop and store   }
  363.   { the last event result.  If the result indicates the user  }
  364.   { did NOT cancel the dialog AND the user entered data,      }
  365.   { get the data back from the dialog so the caller has       }
  366.   { access to it.                                             }
  367.   {                                                           }
  368.   { --------------------------------------------------------- }
  369.  
  370.  
  371.   if Data <> nil then
  372.     P^.SetData (Data^);
  373.  
  374.   Result := DeskTop^.ExecView (P);
  375.  
  376.   if (Result <> cmCancel) and (Data <> nil) then
  377.     P^.GetData (Data^);
  378.  
  379.  
  380.  
  381.   { -------------------------------------------------------------- }
  382.   {                                                                }
  383.   { Dispose of the dialog and return the last event to the caller. }
  384.   {                                                                }
  385.   { -------------------------------------------------------------- }
  386.  
  387.  
  388.   Dispose (P, Done);
  389.  
  390.   ExecDialog := Result;
  391.  
  392.  
  393. end; { ExecDialog }
  394.  
  395.  
  396.  
  397. { -------------------------------------------------------------------------- }
  398.  
  399.  
  400.  
  401. { STATLN - Start. }
  402.  
  403. function T_Status_Line_Help.Hint (AHelpCtx : Word): String;
  404.  
  405.  
  406.   { -------------------------------------------- }
  407.   {                                              }
  408.   { This function puts a hint on the status line }
  409.   { as to what a menu option is supposed to do.  }
  410.   { Hints are arranged in order by menu.         }
  411.   {                                              }
  412.   { -------------------------------------------- }
  413.  
  414.  
  415. begin
  416.  
  417.   case AHelpCtx of
  418.  
  419.     CmdFile.hcFile_Menu      : Hint := 'This menu contains file and DOS features.';
  420.     CmdFile.hcOpen           : Hint := 'Open a file for editing.';
  421.     CmdFile.hcNew            : Hint := 'Create a new file for editing.';
  422.     CmdFile.hcSave           : Hint := 'Save current file and continue editing.';
  423.     CmdFile.hcSaveDone       : Hint := 'Save current file and close window.';
  424.     CmdFile.hcSaveAs         : Hint := 'Save current file to a different file name.';
  425.     CmdFile.hcChangeDir      : Hint := 'Change to another directory.';
  426.     CmdFile.hcShellToDos     : Hint := 'Drop into MS-DOS command shell.';
  427.     CmdFile.hcExit           : Hint := 'Exit application and return to MS-DOS.';
  428.  
  429.     CmdFile.hcEdit_Menu      : Hint := 'This menu contains cut and paste features.';
  430.     CmdFile.hcUndo           : Hint := 'Undo last non-wordwrap operation.';
  431.     CmdFile.hcCopy           : Hint := 'Copy selected text into clipboard.';
  432.     CmdFile.hcCut            : Hint := 'Delete selected text and put into clipboard.';
  433.     CmdFile.hcPaste          : Hint := 'Paste clipboard contents into document.';
  434.     CmdFile.hcClipboard      : Hint := 'View the contents of the clipboard.';
  435.     CmdFile.hcClear          : Hint := 'Delete selected text, do NOT put in clipboard.';
  436.  
  437.     CmdFile.hcSearch_Menu    : Hint := 'This menu contains find and replace features.';
  438.     CmdFile.hcFind           : Hint := 'Find particular text.';
  439.     CmdFile.hcReplace        : Hint := 'Find text and replace it with new text.';
  440.     CmdFile.hcAgain          : Hint := 'Repeat last FIND or SEARCH operation.';
  441.  
  442.     CmdFile.hcWindows_Menu   : Hint := 'This menu contains windowing features.';
  443.     CmdFile.hcResize         : Hint := 'Change current window size and/or position.';
  444.     CmdFile.hcZoom           : Hint := 'Toggle current window to full/normal size.';
  445.     CmdFile.hcNext           : Hint := 'Go to next window.';
  446.     CmdFIle.hcPrev           : Hint := 'Go to previous window.';
  447.     CmdFile.hcClose          : Hint := 'Close current window.';
  448.     CmdFile.hcTile           : Hint := 'Arrange desktop windows into tile pattern.';
  449.     CmdFile.hcCascade        : Hint := 'Arrange desktop windows into cascade pattern.';
  450.  
  451.     CmdFile.hcDesktop_Menu   : Hint := 'This menu contains editor/program options.';
  452.     CmdFile.hcLoadDesktop    : Hint := 'Load contents of previous desktop.';
  453.     CmdFile.hcSaveDesktop    : Hint := 'Save contents of current desktop.';
  454.     CmdFile.hcToggleVideo    : Hint := ' Toggle between 25 and 43/50 line screen.';
  455.  
  456.     CmdFile.hckbAlt          : Hint := '[ALT] KEY';
  457.     CmdFile.hckbCtrl         : Hint := '[CTRL] KEY';
  458.     CmdFile.hckbShift        : Hint := '[SHIFT] KEY';
  459.  
  460.     Views.hcDragging         : Hint := 'RESIZE VIEW';
  461.     $FFFF                    : Hint := 'HELP MODE';
  462.  
  463.    else
  464.      Hint := '';
  465.    end;
  466.  
  467.  
  468. end; { T_Status_Line.Hint }
  469.  
  470. { STATLN - Stop. } { Function responsible for putting menu help on status line. }
  471.  
  472.  
  473.  
  474. { -------------------------------------------------------------------------- }
  475.  
  476.  
  477.  
  478. constructor T_EditDemo.Init;
  479.  
  480.  
  481.   { --------------------------------------------------------------------- }
  482.   {                                                                       }
  483.   { This constructor registers all associated TPU's, initializes buffers, }
  484.   { and sets up any unique processes for the application.                 }
  485.   {                                                                       }
  486.   { --------------------------------------------------------------------- }
  487.  
  488.  
  489. CONST
  490.  
  491.   { COLORS - Start. }
  492.  
  493.   P : array[App.apColor..App.apMonochrome] of string[Length (New_Colors)] =
  494.       (App.CColor, App.CBlackWhite, App.CMonochrome);
  495.  
  496.   { COLORS - Stop. } { Pointer to array that holds application color palette. }
  497.  
  498. VAR
  499.  
  500.   Counter     : Integer;                { General purpose index counter.    }
  501.   Event       : Drivers.TEvent;         { Object to push onto event queue.  }
  502.   File_Name   : DOS.PathStr;            { String to hold default file name. }
  503.  
  504. begin
  505.  
  506.  
  507.  
  508.   { ---------------------------------------------- }
  509.   {                                                }
  510.   { System.File mode controls open but not create. }
  511.   { Do a fixup so networks don't run into hassles. }
  512.   {                                                }
  513.   { ---------------------------------------------- }
  514.  
  515.  
  516.   if Lo (DosVersion) >= 3 then
  517.     System.FileMode := $20        { OPEN Read_Only + Deny_Write }
  518.   else
  519.     System.FileMode := $0;        { ATTR:  Read_Only            }
  520.  
  521.  
  522.  
  523.   { ---------------------------------------- }
  524.   {                                          }
  525.   { Allocate a buffer for use by the editor. }
  526.   { Call ancestor Init constructor and then  }
  527.   { register all required object streams.    }
  528.   {                                          }
  529.   { ---------------------------------------- }
  530.  
  531.  
  532.   EditPkg.Initialize_The_Editor;
  533.  
  534.   App.TApplication.Init;
  535.  
  536.    Objects.RegisterObjects;
  537.      Views.RegisterViews;
  538.      Menus.RegisterMenus;
  539.    Dialogs.RegisterDialogs;
  540.        App.RegisterApp;
  541.   Helpfile.RegisterHelpFile;
  542.    NewEdit.RegisterEditors;
  543.  
  544.  
  545.  
  546.   { ------------------------------------------------- }
  547.   {                                                   }
  548.   { The GADGETS heap view is a handy little critter,  }
  549.   { especially for ensuring we allocate/deallocate    }
  550.   { objects correctly.  So I included it.  Initialize }
  551.   { it, and load a previous desktop, if any.          }
  552.   {                                                   }
  553.   { ------------------------------------------------- }
  554.  
  555.  
  556.   { MEMWIN  - Start. }
  557.   { DESKTOP - Start. }
  558.  
  559.   Insert_Memory_Indicator;
  560.   Load_Desktop;
  561.  
  562.   { DESKTOP - Stop. } { Load previous desktop, if any.          }
  563.   { MEMWIN  - Stop. } { Insert heap view window on status line. }
  564.  
  565.  
  566.  
  567.   { ---------------------------------------------- }
  568.   {                                                }
  569.   { Disable commands that are of no immediate use. }
  570.   { Note that not all of these are necessary, for  }
  571.   { you can change the menus to suit your tastes.  }
  572.   { I have commented out all those not used here.  }
  573.   {                                                }
  574.   { ---------------------------------------------- }
  575.  
  576.  
  577.   DisableCommands ([NewEdit.cmFind,
  578.                     NewEdit.cmReplace,
  579.                     NewEdit.cmSave,
  580.                     NewEdit.cmSaveAs,
  581.                     NewEdit.cmSaveDone,
  582.                     NewEdit.cmSearchAgain,
  583.                     Views.cmCascade,
  584.                     Views.cmClear,
  585.                     Views.cmCopy,
  586.                     Views.cmCut,
  587.                     Views.cmPaste,
  588.                     Views.cmTile,
  589.                     Views.cmUndo]);
  590.  
  591.                     { NewEdit.cmCenterText,  }
  592.                     { NewEdit.cmIndentMode,  }
  593.                     { NewEdit.cmJumpLine,    }
  594.                     { NewEdit.cmJumpMark1,   }
  595.                     { NewEdit.cmJumpMark1,   }
  596.                     { NewEdit.cmJumpMark2,   }
  597.                     { NewEdit.cmJumpMark3,   }
  598.                     { NewEdit.cmJumpMark4,   }
  599.                     { NewEdit.cmJumpMark5,   }
  600.                     { NewEdit.cmJumpMark6,   }
  601.                     { NewEdit.cmJumpMark7,   }
  602.                     { NewEdit.cmJumpMark8,   }
  603.                     { NewEdit.cmJumpMark9,   }
  604.                     { NewEdit.cmJumpMark0,   }
  605.                     { NewEdit.cmReformDoc,   }
  606.                     { NewEdit.cmReformPara,  }
  607.                     { NewEdit.cmRightMargin, }
  608.                     { NewEdit.cmSetMark1,    }
  609.                     { NewEdit.cmSetMark1,    }
  610.                     { NewEdit.cmSetMark2,    }
  611.                     { NewEdit.cmSetMark3,    }
  612.                     { NewEdit.cmSetMark4,    }
  613.                     { NewEdit.cmSetMark5,    }
  614.                     { NewEdit.cmSetMark6,    }
  615.                     { NewEdit.cmSetMark7,    }
  616.                     { NewEdit.cmSetMark8,    }
  617.                     { NewEdit.cmSetMark9,    }
  618.                     { NewEdit.cmSetMark0,    }
  619.                     { NewEdit.cmSetTabs,     }
  620.                     { NewEdit.cmWordWrap]);  }
  621.  
  622.  
  623.  
  624.   { ---------------------------------------- }
  625.   {                                          }
  626.   { We need to disable the 43/50 column mode }
  627.   { if the video card doesn't support it.    }
  628.   {                                          }
  629.   { ---------------------------------------- }
  630.  
  631.  
  632.   { SCRNSZ - Start. }
  633.  
  634.   if Drivers.HiresScreen = False then
  635.     DisableCommands ([CmdFile.cmToggleVideo]);
  636.  
  637.   { SCRNSZ - Stop. }
  638.  
  639.  
  640.  
  641.   { ------------------------------------------------- }
  642.   {                                                   }
  643.   { Call the EDITPKG unit to intialize the clipboard. }
  644.   {                                                   }
  645.   { ------------------------------------------------- }
  646.  
  647.  
  648.   EditPkg.Initialize_The_Clipboard;
  649.  
  650.  
  651.  
  652.   { -------------------------------------------------------- }
  653.   {                                                          }
  654.   { We allow the user to pass a file name parameter from DOS }
  655.   { when running the program.  If a parameter was passed in  }
  656.   { call the editor to open an edit window for the file.     }
  657.   {                                                          }
  658.   { -------------------------------------------------------- }
  659.  
  660.  
  661.   for Counter := 1 to ParamCount do
  662.     if (pos ('*', ParamStr (Counter)) = 0) and (pos ('?', ParamStr (Counter)) = 0) then
  663.       EditPkg.Open_Editor (ParamStr (Counter), TRUE);
  664.  
  665.  
  666.  
  667.   { ------------------------------------------------------------ }
  668.   {                                                              }
  669.   { The desktop is ready, so now a brief word from your sponsor. }
  670.   { Push cmAbout event on the event queue so the About box       }
  671.   { will appear when we first run the application.               }
  672.   {                                                              }
  673.   { ------------------------------------------------------------ }
  674.  
  675.  
  676.   Event.What := Drivers.evCommand;
  677.   Event.command := CmdFile.cmAbout;
  678.   PutEvent (Event);
  679.  
  680.  
  681. end; { T_EditDemo.Init }
  682.  
  683.  
  684.  
  685. { -------------------------------------------------------------------------- }
  686.  
  687.  
  688.  
  689. destructor T_EditDemo.Done;
  690.  
  691.  
  692.   { --------------------------------------------------------------------- }
  693.   {                                                                       }
  694.   { This destructor deallocates any unique processes for the application. }
  695.   { Currently it saves the current desktop, calls the ancestor done       }
  696.   { method, and then deallocates any buffers set up by the editor.        }
  697.   {                                                                       }
  698.   { --------------------------------------------------------------------- }
  699.  
  700.  
  701. begin
  702.  
  703.   Save_Desktop;
  704.   App.TApplication.Done;
  705.   EditPkg.Deallocate_The_Editor;
  706.  
  707.  
  708. end; { T_EditDemo.Done }
  709.  
  710.  
  711.  
  712. { -------------------------------------------------------------------------- }
  713.  
  714.  
  715.  
  716. { DESKTOP - Start. }
  717.  
  718. procedure T_EditDemo.DesktopReadViews (VAR S : TStream);
  719.  
  720.  
  721.   { ------------------------------------------- }
  722.   {                                             }
  723.   { This procedure closes all desktop views     }
  724.   { and then reads in each view from a previous }
  725.   { desktop, putting it on the current desktop. }
  726.   {                                             }
  727.   { ------------------------------------------- }
  728.  
  729.  
  730. VAR
  731.  
  732.   P : Views.PView;    { Pointer to each of the desktop views. }
  733.  
  734.  
  735.  
  736.   { -------------------------------------------------------------------------- }
  737.  
  738.  
  739.  
  740.   procedure Command_All (Command_Constant : Word );
  741.  
  742.     procedure Action (P : Views.PView); far;
  743.  
  744.     begin
  745.  
  746.       Message (P, evCommand, Command_Constant, nil);
  747.  
  748.     end; { Action }
  749.  
  750.   begin { Command_All }
  751.  
  752.      Desktop^.ForEach (@Action);
  753.  
  754.   end; { Command_All }
  755.  
  756.  
  757.  
  758.   { -------------------------------------------------------------------------- }
  759.  
  760.  
  761.  
  762.   procedure Close_All_Views;
  763.  
  764.   begin
  765.  
  766.      Command_All (cmClose);
  767.  
  768.   end; { Close_All_Views }
  769.  
  770.  
  771.  
  772.   { -------------------------------------------------------------------------- }
  773.  
  774.  
  775.  
  776. begin { DesktopReadViews }
  777.  
  778.  
  779.  
  780.   { ----------------------------------------------------- }
  781.   {                                                       }
  782.   { If we don't have a valid desktop, forget it and exit. }
  783.   { Otherwise, close all current views on the desktop.    }
  784.   {                                                       }
  785.   { ----------------------------------------------------- }
  786.  
  787.  
  788.   if not Desktop^.Valid (Views.cmClose) then
  789.     Exit;
  790.  
  791.   Close_All_Views;
  792.  
  793.  
  794.  
  795.   { -------------------------------------------------------- }
  796.   {                                                          }
  797.   { The first item in any previous desktop that was saved is }
  798.   { the Current_Screen_Mode.  Get it and determine if it was }
  799.   { 43/50 line mode.  If so, toggle the screen to that mode. }
  800.   {                                                          }
  801.   { -------------------------------------------------------- }
  802.  
  803.  
  804.   S.Read (Current_Screen_Mode, SizeOf (Current_Screen_Mode));
  805.  
  806.   if (Current_Screen_Mode AND Drivers.smFont8x8 = Drivers.smFont8x8) then
  807.     Toggle_Video_Mode;
  808.  
  809.  
  810.  
  811.   { ----------------------------------------------- }
  812.   {                                                 }
  813.   { Now read in each view from the previous desktop }
  814.   { and insert it on our desktop.  Exit when there  }
  815.   { are no more views to read in.                   }
  816.   {                                                 }
  817.   { ----------------------------------------------- }
  818.  
  819.  
  820.   while True do
  821.     begin
  822.  
  823.       P := Views.PView (S.Get);
  824.  
  825.       Desktop^.InsertBefore (App.Application^.ValidView (P), Desktop^.Last);
  826.  
  827.       if P = nil then
  828.         Exit;
  829.  
  830.     end;
  831.  
  832.  
  833. end; { T_EditDemo.DesktopReadViews }
  834.  
  835. { DESKTOP - Stop. } { Procedure responsible for actually reading desktop file. }
  836.  
  837.  
  838.  
  839. { -------------------------------------------------------------------------- }
  840.  
  841.  
  842.  
  843. { DESKTOP - Start. }
  844.  
  845. procedure T_EditDemo.DesktopWriteViews (VAR S : TStream);
  846.  
  847.  
  848.   { ----------------------------------------------- }
  849.   {                                                 }
  850.   { This procedure writes all current desktop views }
  851.   { and and the Current_Video_Mode to the disk.     }
  852.   {                                                 }
  853.   { ----------------------------------------------- }
  854.  
  855.  
  856. VAR
  857.  
  858.   P : Views.PView;    { Pointer to each of the desktop views. }
  859.  
  860.  
  861.  
  862.   { -------------------------------------------------------------------------- }
  863.  
  864.  
  865.  
  866.   procedure WriteView (P : PView); far;
  867.  
  868.     { ----------------------------------------------------------- }
  869.     {                                                             }
  870.     { A local procedure that actually puts all the views to disk. }
  871.     {                                                             }
  872.     { ----------------------------------------------------------- }
  873.  
  874.   begin
  875.  
  876.     if P <> Desktop^.Last then
  877.        S.Put (P);
  878.  
  879.   end; { WriteView }
  880.  
  881.  
  882.  
  883.   { -------------------------------------------------------------------------- }
  884.  
  885.  
  886.  
  887. begin { DesktopWriteViews }
  888.  
  889.  
  890.  
  891.   { ----------------------------------------------------------------------- }
  892.   {                                                                         }
  893.   { First write the Current_Video_Mode to disk, and then each desktop view. }
  894.   {                                                                         }
  895.   { ----------------------------------------------------------------------- }
  896.  
  897.  
  898.   S.Write (Current_Screen_Mode, SizeOf (Current_Screen_Mode));
  899.  
  900.   Desktop^.ForEach (@WriteView);
  901.   S.Put (nil);
  902.  
  903.  
  904. end; { T_EditDemo.DesktopWriteViews }
  905.  
  906. { DESKTOP - Stop. } { Procedure responsible for actually writing desktop file. }
  907.  
  908.  
  909.  
  910. { ------------------------------------------------------------------------ }
  911.  
  912.  
  913.  
  914. procedure T_EditDemo.GetEvent (var Event : Drivers.TEvent);
  915.  
  916.  
  917.   { ---------------------------------------- }
  918.   {                                          }
  919.   { This procedure intercepts system events, }
  920.   { constantly looking to see if help has    }
  921.   { been requested.                          }
  922.   {                                          }
  923.   { ---------------------------------------- }
  924.  
  925.  
  926. VAR
  927.  
  928.   File_Mode   : Word;                   { Used for networking access.        }
  929.   Help_Stream : Objects.PDosStream;     { DOS stream to place help file on.  }
  930.   Help_File   : HelpFile.PHelpFile;     { Name of the help file.             }
  931.   W           : Views.PWindow;          { Help file window.                  }
  932.  
  933.  
  934. CONST
  935.  
  936.   Help_In_Use : Boolean = False; { Prevents user from opening more than 1 help file. }
  937.  
  938.  
  939.  
  940.   { -------------------------------------------------------------------------- }
  941.  
  942.  
  943.  
  944.   function Calc_Help_Name : DOS.PathStr;
  945.  
  946.  
  947.     { ------------------------------------------------ }
  948.     {                                                  }
  949.     { This function calculates what the help file name }
  950.     { is, based on the application name being run.     }
  951.     {                                                  }
  952.     { ------------------------------------------------ }
  953.  
  954.  
  955.   VAR
  956.  
  957.     Directory      : DOS.DirStr;        { Home directory of the application. }
  958.     EXE_File       : DOS.PathStr;       { Name of the EDITDEMO.EXE file.     }
  959.     File_Extension : DOS.ExtStr;        { The file name extension.           }
  960.     File_Name      : DOS.NameStr;       { The file name minus the extension. }
  961.  
  962.  
  963.   begin
  964.  
  965.  
  966.     { -------------------------------------------------------- }
  967.     {                                                          }
  968.     { Check for the DOS version.  If it is >= 3 the file name  }
  969.     { is in parameter #0 of the arguments passed into program. }
  970.     { Otherwise, we have to search for the file in the PATH.   }
  971.     {                                                          }
  972.     { -------------------------------------------------------- }
  973.  
  974.  
  975.     if Lo (DOS.DosVersion) >= 3 then
  976.       EXE_File := ParamStr (0)
  977.     else
  978.       EXE_File := DOS.FSearch (Application_Name, GetEnv ('PATH'));
  979.  
  980.  
  981.  
  982.     { ---------------------------------------------- }
  983.     {                                                }
  984.     { Split the File_Name into its component parts.  }
  985.     { Search for the help file in current directory. }
  986.     {                                                }
  987.     { ---------------------------------------------- }
  988.  
  989.  
  990.     DOS.FSplit (EXE_File, Directory, File_Name, File_Extension);
  991.  
  992.     if Directory[Length (Directory)] = '\' then
  993.       Dec (Directory[0]);
  994.  
  995.     Calc_Help_Name := DOS.FSearch (Application_Name + '.HLP', Directory);
  996.  
  997.   end; { Calc_Help_Name }
  998.  
  999.  
  1000.  
  1001.   { -------------------------------------------------------------------------- }
  1002.  
  1003.  
  1004.  
  1005. begin { GetEvent }
  1006.  
  1007.  
  1008.  
  1009.   { -------------------------------------------------------------- }
  1010.   {                                                                }
  1011.   { Get the event and see if 1) it is for help and 2) help is NOT  }
  1012.   { being used.  If true, then allocate a stream and put the help  }
  1013.   { file on it.  Then test if stream opened OK.  If not, tell user }
  1014.   { couldn't open the help file.  Otherwise, open a help view.     }
  1015.   { Clear the event and set Help_In_Use to FALSE before exiting.   }
  1016.   {                                                                }
  1017.   { -------------------------------------------------------------- }
  1018.  
  1019.  
  1020.   App.TApplication.GetEvent (Event);
  1021.  
  1022.   case Event.What of
  1023.     evCommand:
  1024.  
  1025.       if (Event.Command = Views.cmHelp) and not Help_In_Use then
  1026.         begin
  1027.  
  1028.  
  1029.  
  1030.           { ----------------------------------------------------- }
  1031.           {                                                       }
  1032.           { Help requested.  Disallow use of multiple help files. }
  1033.           {                                                       }
  1034.           { ----------------------------------------------------- }
  1035.  
  1036.  
  1037.           Help_In_Use := True;
  1038.  
  1039.  
  1040.  
  1041.           { ----------------------------------------- }
  1042.           {                                           }
  1043.           { Set File_Mode to default to read only.    }
  1044.           { If MS-DOS is 3 or better set to read only }
  1045.           { and deny write privleges.                 }
  1046.           {                                           }
  1047.           { ----------------------------------------- }
  1048.  
  1049.  
  1050.           File_Mode := Objects.stOpenRead;
  1051.  
  1052.           if Lo (DosVersion) >= 3 then
  1053.             File_Mode := $3d20;
  1054.  
  1055.  
  1056.  
  1057.           { -------------------------------------------------------- }
  1058.           {                                                          }
  1059.           { Calculate help file name based on the applications name. }
  1060.           {                                                          }
  1061.           { -------------------------------------------------------- }
  1062.  
  1063.  
  1064.           Help_Stream := New (Objects.PDosStream, Init (Calc_Help_Name, File_Mode));
  1065.           Help_File := New (HelpFile.PHelpFile, Init (Help_Stream));
  1066.  
  1067.  
  1068.  
  1069.           { ------------------------------------------------------------------- }
  1070.           {                                                                     }
  1071.           { Let the user know if there was a problem opening/finding help file. }
  1072.           {                                                                     }
  1073.           { ------------------------------------------------------------------- }
  1074.  
  1075.  
  1076.           if Help_Stream^.Status <> Objects.stOk then
  1077.             begin
  1078.  
  1079.               MsgBox.MessageBox (^C'Could not open help file.',
  1080.                                  nil, MsgBox.mfError + MsgBox.mfOkButton);
  1081.               Dispose (Help_File, Done);
  1082.  
  1083.             end
  1084.  
  1085.           else
  1086.  
  1087.             begin
  1088.  
  1089.  
  1090.  
  1091.               { --------------------------------------------------- }
  1092.               {                                                     }
  1093.               { Allocate the help view.  If we've got enough memory }
  1094.               { attach the help view to the desktop.  Dispose the   }
  1095.               { view when we are done, and clear the event.         }
  1096.               {                                                     }
  1097.               { --------------------------------------------------- }
  1098.  
  1099.  
  1100.               W := New (HelpFile.PHelpWindow, Init (Help_File, GetHelpCtx));
  1101.  
  1102.               if ValidView (W) <> nil then
  1103.               begin
  1104.  
  1105.                 W^.HelpCtx := $FFFF;
  1106.                 ExecView (W);
  1107.                 Dispose (W, Done);
  1108.  
  1109.               end;
  1110.  
  1111.               ClearEvent (Event);
  1112.  
  1113.             end;
  1114.  
  1115.  
  1116.  
  1117.           { --------------------------------------------------------------- }
  1118.           {                                                                 }
  1119.           { Signal that a help window can is allowed to be be opened again. }
  1120.           {                                                                 }
  1121.           { --------------------------------------------------------------- }
  1122.  
  1123.  
  1124.           Help_In_Use := False;
  1125.  
  1126.         end;
  1127.  
  1128.     Drivers.evMouseDown:
  1129.  
  1130.     if Event.Buttons <> 1 then
  1131.       Event.What := Drivers.evNothing;
  1132.  
  1133.   end;
  1134.  
  1135.  
  1136. end; { T_EditDemo.GetEvent }
  1137.  
  1138.  
  1139.  
  1140. { -------------------------------------------------------------------------- }
  1141.  
  1142.  
  1143.  
  1144. { COLORS - Start. }
  1145.  
  1146. function T_EditDemo.GetPalette : Views.PPalette;
  1147.  
  1148.  
  1149.   { --------------------------------------------- }
  1150.   {                                               }
  1151.   { This is an oveload method on TApplication.    }
  1152.   { We simply reset the application COLOR palette }
  1153.   { with our New_Colors.                          }
  1154.   {                                               }
  1155.   { --------------------------------------------- }
  1156.  
  1157.  
  1158. CONST
  1159.  
  1160.   CNewBlackWhite = App.CBlackWhite  + HelpFile.CHelpBlackWhite;
  1161.   CNewColor      = New_Colors       + HelpFile.CHelpColor;
  1162.   CNewMonochrome = App.CMonochrome  + HelpFile.CHelpMonochrome;
  1163.  
  1164.   P : array[App.apColor..App.apMonochrome] of string[Length (CNewColor)] = (CNewColor,
  1165.                                                                             CNewBlackWhite,
  1166.                                                                             CNewMonochrome);
  1167.  
  1168. begin
  1169.  
  1170.   GetPalette := @P[AppPalette];
  1171.  
  1172.  
  1173. end; { T_EditDemo.GetPalette }
  1174.  
  1175. { COLORS - Stop. } { Required to replace current palatte with our New_Colors. }
  1176.  
  1177.  
  1178.  
  1179. { -------------------------------------------------------------------------- }
  1180.  
  1181.  
  1182.  
  1183. procedure T_EditDemo.HandleEvent (var Event : TEvent);
  1184.  
  1185.  
  1186.   { ----------------------------------------------- }
  1187.   {                                                 }
  1188.   { This procedure handles all the system events.   }
  1189.   { If at all possible, try to keep event handlers  }
  1190.   { local to this procedure, in alphabetical order. }
  1191.   {                                                 }
  1192.   { ----------------------------------------------- }
  1193.  
  1194.  
  1195.  
  1196.   { ------------------------------------------------------------------------ }
  1197.  
  1198.  
  1199.  
  1200.   procedure About_Dialog;
  1201.  
  1202.  
  1203.     { -------------------------------------------------------------- }
  1204.     {                                                                }
  1205.     { This procedure simply brings the "About The Program" dialog    }
  1206.     { up for the user to see.  It's only used once so I put it here. }
  1207.     { You can change the text to anything you want.  Remember that   }
  1208.     { there is a 128 character limitation on static text!            }
  1209.     {                                                                }
  1210.     { -------------------------------------------------------------- }
  1211.  
  1212.  
  1213.   VAR
  1214.  
  1215.     D : Dialogs.PDialog;     { The Dialog box.        }
  1216.     R : TRect;               { The bounds of the box. }
  1217.  
  1218.  
  1219.   begin
  1220.  
  1221.  
  1222.     { ------------------------------------------------------------ }
  1223.     {                                                              }
  1224.     { Assign the bounds of the box, then insert the label into it. }
  1225.     { Now shrink it so we are inside of frame., Insert some text   }
  1226.     { that is centered into it, then assign an OK button.          }
  1227.     {                                                              }
  1228.     { ------------------------------------------------------------ }
  1229.  
  1230.  
  1231.     R.Assign (0, 0, 50, 20);
  1232.     D := New (Dialogs.PDialog, Init (R, 'About The Program'));
  1233.  
  1234.     with D^ do
  1235.       begin
  1236.         Options := Options or Views.ofCentered;
  1237.         D^.HelpCtx := CmdFile.hcDAbout;
  1238.  
  1239.         R.Grow (-1, -1);
  1240.         Dec (R.B.Y, 3);
  1241.         Insert (New (Dialogs.PStaticText, Init (R,       + #13       +
  1242.           ^C'NewEdit v1.00 Demonstration Program'        + #13 + #13 +
  1243.           ^C'Author:  Al Andersen'                       + #13       +
  1244.           ^C'PO Box 2436'                                + #13 +
  1245.           ^C'Sierra Vista, AZ 85636'                     + #13 + #13 +
  1246.           ^C'CIS ID: 71610,3214'                         + #13       +
  1247.           ^C'Internet: aandersen@huachuca-emh2.army.mil' + #13 + #13 +
  1248.           ^C'Special Thanks To:'                         + #13 + #13 +
  1249.           ^C'Johnathan Stein and Tom Campbell'           + #13 +
  1250.           ^C'for their unwavering support.')));
  1251.  
  1252.         R.Assign (20, 17, 30, 19);
  1253.         Insert (New (Dialogs.PButton, Init (R, 'O~K~', Views.cmOk, Dialogs.bfDefault)));
  1254.  
  1255.       end;
  1256.  
  1257.  
  1258.  
  1259.     { ------------------------------------------------------------------- }
  1260.     {                                                                     }
  1261.     { Test to see if the view is valid, and if so, put it on the desktop. }
  1262.     { Oh yeah, don't forget to dispose of the view!                       }
  1263.     {                                                                     }
  1264.     { ------------------------------------------------------------------- }
  1265.  
  1266.  
  1267.     if ValidView (D) <> nil then
  1268.       ExecDialog (D, nil);
  1269.  
  1270.  
  1271.   end; { About_Dialog }
  1272.  
  1273.  
  1274.  
  1275.   { ------------------------------------------------------------------------ }
  1276.  
  1277.  
  1278.  
  1279.   procedure Cascade;
  1280.  
  1281.  
  1282.     { --------------------------------------------------- }
  1283.     {                                                     }
  1284.     { This procedure gets the extent of the desktop and   }
  1285.     { then puts open windows into a "cascade" pattern.    }
  1286.     {                                                     }
  1287.     { --------------------------------------------------- }
  1288.  
  1289.  
  1290.   VAR
  1291.  
  1292.     R : TRect;   { Bounds of the desktop. }
  1293.  
  1294.   begin
  1295.  
  1296.     Desktop^.GetExtent (R);
  1297.     Desktop^.Cascade (R);
  1298.  
  1299.  
  1300.   end; { Cascade }
  1301.  
  1302.  
  1303.  
  1304.   { ------------------------------------------------------------------------ }
  1305.  
  1306.  
  1307.  
  1308.   procedure Change_Directory;
  1309.  
  1310.  
  1311.     { --------------------------------------------------------------- }
  1312.     {                                                                 }
  1313.     { This procedure brings up a "tree" dialog to change directories. }
  1314.     {                                                                 }
  1315.     { --------------------------------------------------------------- }
  1316.  
  1317.  
  1318.   VAR
  1319.  
  1320.      D : Dialogs.PDialog;
  1321.  
  1322.   begin
  1323.  
  1324.      D := New (StdDlg.PChDirDialog, Init (StdDlg.cdNormal, 0));
  1325.      D^.HelpCtx := CmdFile.hcDDirName;
  1326.      ExecDialog (D, nil);
  1327.  
  1328.   end; { Change_Directory }
  1329.  
  1330.  
  1331.  
  1332.   { ------------------------------------------------------------------------ }
  1333.  
  1334.  
  1335.   procedure Quit_Program;
  1336.  
  1337.  
  1338.     { ------------------------------------------ }
  1339.     {                                            }
  1340.     { This procedure calls EndModal to close all }
  1341.     { views before terminating the application.  }
  1342.     { Yeah, I know, but its the way I do things! }
  1343.     {                                            }
  1344.     { ------------------------------------------ }
  1345.  
  1346.  
  1347.   begin
  1348.  
  1349.     TView.EndModal (cmQuit);
  1350.  
  1351.  
  1352.   end; { Quit_Program}
  1353.  
  1354.  
  1355.  
  1356.   { ------------------------------------------------------------------------ }
  1357.  
  1358.  
  1359.  
  1360.   procedure Shell_To_DOS;
  1361.  
  1362.  
  1363.     { --------------------------------------------------- }
  1364.     {                                                     }
  1365.     { This procedure does the necessary memory management }
  1366.     { to allow the user to shell to MS-DOS and reenter    }
  1367.     { the program again.                                  }
  1368.     {                                                     }
  1369.     { --------------------------------------------------- }
  1370.  
  1371.  
  1372.  
  1373.     { ---------------------------------------------------------------------- }
  1374.  
  1375.  
  1376.  
  1377.     function Buffers_In_Use : Boolean;
  1378.  
  1379.  
  1380.       { ------------------------------------------------------------ }
  1381.       {                                                              }
  1382.       { This is a local procedure that determins the buffers in use. }
  1383.       { It's required to determine where to SetMemTop before/after   }
  1384.       { shelling to MS-DOS.                                          }
  1385.       {                                                              }
  1386.       { ------------------------------------------------------------ }
  1387.  
  1388.  
  1389.     begin
  1390.  
  1391.       Buffers_In_Use := (PtrRec (HeapEnd).Seg <> BufHeapEnd) and (BufHeapEnd <> 0);
  1392.  
  1393.  
  1394.     end; { Buffers_In_Use }
  1395.  
  1396.  
  1397.  
  1398.     { ---------------------------------------------------------------------- }
  1399.  
  1400.  
  1401.  
  1402.   begin { Shell_To_Dos }
  1403.  
  1404.  
  1405.  
  1406.     { ------------------------------------------- }
  1407.     {                                             }
  1408.     { If we've got a good desktop we need to do   }
  1409.     { some house cleaning before we go to MS-DOS. }
  1410.     {                                             }
  1411.     { ------------------------------------------- }
  1412.  
  1413.  
  1414.     if Desktop <> nil then
  1415.       begin
  1416.         Drivers.DoneSysError;
  1417.         Drivers.DoneEvents;
  1418.         Drivers.DoneVideo;
  1419.         Memory.DoneMemory;
  1420.       end;
  1421.  
  1422.  
  1423.  
  1424.     { ----------------------------------------------- }
  1425.     {                                                 }
  1426.     { Now see if we've allocated any special buffers, }
  1427.     { i.e. the editor, and SetMemTop accordingly.     }
  1428.     {                                                 }
  1429.     { ----------------------------------------------- }
  1430.  
  1431.  
  1432.     if Buffers_In_Use then
  1433.       SetMemTop (Ptr (BufHeapPtr, 0))
  1434.     else
  1435.       SetMemTop (HeapPtr);
  1436.  
  1437.  
  1438.  
  1439.     { ------------------------------------ }
  1440.     {                                      }
  1441.     { Always tell the user what's required }
  1442.     { to get back into the application.    }
  1443.     { Then go to MS-DOS.  Reverse all that }
  1444.     { we did to bet back into the program. }
  1445.     {                                      }
  1446.     { ------------------------------------ }
  1447.  
  1448.  
  1449.     PrintStr ('Type ''EXIT'' to return...');
  1450.     SwapVectors;
  1451.  
  1452.     DOS.Exec (GetEnv ('COMSPEC'), '');
  1453.     SwapVectors;
  1454.  
  1455.     if Buffers_In_Use then
  1456.       SetMemTop (Ptr (BufHeapEnd, 0))
  1457.     else
  1458.       SetMemTop ( HeapEnd);
  1459.  
  1460.    if Desktop <> nil then
  1461.      begin
  1462.        Memory.InitMemory;
  1463.        Drivers.InitVideo;
  1464.        Drivers.InitEvents;
  1465.        Drivers.InitSysError;
  1466.        App.Application^.Redraw;
  1467.      end;
  1468.  
  1469.  
  1470.  
  1471.     { ---------------------------------------- }
  1472.     {                                          }
  1473.     { If all went well, exit this procedure.   }
  1474.     { Otherwise, tell user there is a problem. }
  1475.     {                                          }
  1476.     { ---------------------------------------- }
  1477.  
  1478.  
  1479.     if DosError = 0 then
  1480.       Exit;
  1481.  
  1482.     MsgBox.MessageBox (^C'DOS Reports an error!', nil,
  1483.                        MsgBox.mfInformation + MsgBox.mfOKbutton);
  1484.  
  1485.  
  1486.   end; { Shell_To_DOS }
  1487.  
  1488.  
  1489.  
  1490.   { ------------------------------------------------------------------------ }
  1491.  
  1492.  
  1493.  
  1494.   procedure Tile;
  1495.  
  1496.  
  1497.     { ------------------------------------------------- }
  1498.     {                                                   }
  1499.     { This procedure gets the extent of the desktop and }
  1500.     { then puts all open windows into a "tile pattern." }
  1501.     {                                                   }
  1502.     { ------------------------------------------------- }
  1503.  
  1504.  
  1505.   VAR
  1506.  
  1507.     R : TRect;  { Bounds of the desktop. }
  1508.  
  1509.   begin
  1510.  
  1511.     Desktop^.GetExtent (R);
  1512.     Desktop^.Tile (R);
  1513.  
  1514.  
  1515.   end; { Tile }
  1516.  
  1517.  
  1518.  
  1519.   { -------------------------------------------------------------------------}
  1520.  
  1521.  
  1522.  
  1523. { -------------------------------------- }
  1524. {                                        }
  1525. { Main body of T_EditDemo.HandleEvent.   }
  1526. { All commands are dispatched from here. }
  1527. {                                        }
  1528. { -------------------------------------- }
  1529.  
  1530.  
  1531. begin
  1532.  
  1533.   App.TApplication.HandleEvent (Event);
  1534.  
  1535.   case Event.What of evCommand:
  1536.  
  1537.     begin
  1538.  
  1539.       case Event.Command of
  1540.  
  1541.         CmdFile.cmAbout        : About_Dialog;
  1542.         CmdFile.cmChangeDir    : Change_Directory;
  1543.         CmdFile.cmClipboard    : EditPkg.Show_ClipBoard;
  1544.  
  1545.         { DESKTOP - Start. }
  1546.  
  1547.         CmdFile.cmLoadDesktop  : Load_Desktop;
  1548.  
  1549.         { DESKTOP - Stop. }
  1550.  
  1551.         CmdFile.cmNew          : EditPkg.Open_Editor ('', True);
  1552.         CmdFile.cmOpen         : EditPkg.Run_The_Editor;
  1553.  
  1554.  
  1555.         { DESKTOP - Start. }
  1556.  
  1557.         CmdFile.cmSaveDesktop  : Save_Desktop;
  1558.  
  1559.         { DESKTOP - Stop. }
  1560.  
  1561.         CmdFile.cmShellToDos   : Shell_To_DOS;
  1562.  
  1563.         { SCRNSZ - Start. }
  1564.  
  1565.         CmdFile.cmToggleVideo  : Toggle_Video_Mode;
  1566.  
  1567.         { SCRNSZ - Stop. }
  1568.  
  1569.         Views.cmCascade        : Cascade;
  1570.         Views.cmQuit           : Quit_Program;
  1571.         Views.cmTile           : Tile;
  1572.  
  1573.       else
  1574.  
  1575.         Exit;
  1576.  
  1577.       end;
  1578.  
  1579.       ClearEvent (Event);
  1580.  
  1581.     end;
  1582.   end;
  1583.  
  1584.  
  1585. end; { TApplication.HandleEvent }
  1586.  
  1587.  
  1588.  
  1589. { ---------------------------------------------------------------------------}
  1590.  
  1591.  
  1592.  
  1593. procedure T_EditDemo.Idle;
  1594.  
  1595.  
  1596.   { ---------------------------------------------------------- }
  1597.   {                                                            }
  1598.   { This function handles events during system idle time.      }
  1599.   { Specifically, toggling on off of menu options that need    }
  1600.   { changing, updating the memory indicator view, and changing }
  1601.   { the status line if Shift, Alt, or Ctrl keys are pressed.   }
  1602.   {                                                            }
  1603.   { ---------------------------------------------------------- }
  1604.  
  1605.  
  1606.  
  1607.   { ------------------------------------------------------------------------ }
  1608.  
  1609.  
  1610.  
  1611.   function Is_Tileable (P : Views.PView) : Boolean; far;
  1612.  
  1613.  
  1614.     { ------------------------------------------ }
  1615.     {                                            }
  1616.     { This is a local function that tests to see }
  1617.     { if views can be tiled and/or cascaded.     }
  1618.     {                                            }
  1619.     { ------------------------------------------ }
  1620.  
  1621.  
  1622.   begin
  1623.  
  1624.     Is_Tileable := P^.Options and Views.ofTileable <> 0;
  1625.  
  1626.   end;
  1627.  
  1628.  
  1629.  
  1630. begin { T_EditDemo.Idle }
  1631.  
  1632.  
  1633.  
  1634.   { ------------------------------------------------ }
  1635.   {                                                  }
  1636.   { We don't have anything real special to do here,  }
  1637.   { so call ancestor Idle method first.  Then update }
  1638.   { the Memory_Indicator view and check to see if    }
  1639.   { the status line needs to be changed.             }
  1640.   {                                                  }
  1641.   { ------------------------------------------------ }
  1642.  
  1643.  
  1644.   App.TApplication.Idle;
  1645.  
  1646.   { MEMWIN - Start. }
  1647.   { STATLN - Start. }
  1648.  
  1649.   Memory_Indicator^.Update;
  1650.   Change_Status_Line;
  1651.  
  1652.   { STATLN - Stop. } { Constantly check if we need to update status line.    }
  1653.   { MEMWIN - Stop. } { Constantly update heap view window to reflect memory. }
  1654.  
  1655.  
  1656.  
  1657.   { ----------------------------------------------------- }
  1658.   {                                                       }
  1659.   { Check to see if first window in desktop can be tiled. }
  1660.   { If it can, then we can toggle the cascade/tile and    }
  1661.   { Next/Prev on.  Once the window disappears, disable    }
  1662.   { the cascade/tile and Next/Prev options.               }
  1663.   {                                                       }
  1664.   { ----------------------------------------------------- }
  1665.  
  1666.  
  1667.   if Desktop^.FirstThat (@Is_Tileable) <> nil then
  1668.     EnableCommands ([Views.cmTile,
  1669.                      Views.cmCascade,
  1670.                      Views.cmNext,
  1671.                      Views.cmPrev])
  1672.   else
  1673.     DisableCommands ([Views.cmTile,
  1674.                       Views.cmCascade,
  1675.                       Views.cmNext,
  1676.                       Views.cmPrev]);
  1677.  
  1678.  
  1679. end; { T_EditDemo.Idle }
  1680.  
  1681.  
  1682.  
  1683. { ---------------------------------------------------------------------------}
  1684.  
  1685.  
  1686.  
  1687. procedure T_EditDemo.InitMenuBar;
  1688.  
  1689.  
  1690.   { --------------------------------------------------------------- }
  1691.   {                                                                 }
  1692.   { This procedure sets up the menu bar and all its pulldown menus. }
  1693.   {                                                                 }
  1694.   { --------------------------------------------------------------- }
  1695.  
  1696.  
  1697. VAR
  1698.  
  1699.   R : TRect;   { Bounds of the desktop. }
  1700.  
  1701. begin
  1702.  
  1703.  
  1704.   { --------------------------------------------------- }
  1705.   {                                                     }
  1706.   { Get the extent of the desktop and drop top line +1. }
  1707.   {                                                     }
  1708.   { --------------------------------------------------- }
  1709.  
  1710.  
  1711.   GetExtent (R);
  1712.   R.B.Y := R.A.Y + 1;
  1713.  
  1714.  
  1715.  
  1716.   { --------------------------------------------------------------------- }
  1717.   {                                                                       }
  1718.   { This is the MenuBar initialization.  Note that it consists            }
  1719.   { of submenus.  The format for declaring a NewItem in a submenu         }
  1720.   { consists of the following:                                            }
  1721.   {                                                                       }
  1722.   { Name         - a string, surrounding select characters with tilde's.  }
  1723.   { Keys         - a string indicating which key is a "hot key" for item. }
  1724.   { Key Command  - TurboVision "kb????" command to bind as hot key.       }
  1725.   { Item Command - TurboVision "cm????" command to bind to item.          }
  1726.   { Help Context - TurboVision help context command to bind to item.      }
  1727.   {                                                                       }
  1728.   { --------------------------------------------------------------------- }
  1729.  
  1730.  
  1731.   MenuBar := New (Menus.PMenuBar, Init (R, NewMenu (
  1732.  
  1733.  
  1734.  
  1735.     { ---------------------------------------- }
  1736.     {                                          }
  1737.     { This is the FILE submenu initialization. }
  1738.     {                                          }
  1739.     { ---------------------------------------- }
  1740.  
  1741.  
  1742.     NewSubMenu ('~F~ile',  CmdFile.hcFile_Menu,     NewMenu (
  1743.  
  1744.       NewItem  ('~O~pen',               'F3',  Drivers.kbF3,       CmdFile.cmOpen,          CmdFile.hcOpen,
  1745.       NewItem  ('~N~ew',                  '',  Drivers.kbNoKey,    CmdFile.cmNew,           CmdFile.hcNew,
  1746.  
  1747.       NewLine  (
  1748.  
  1749.       NewItem  ('Save ~C~ontinue',      'F2',  Drivers.kbF2,       NewEdit.cmSave,          CmdFile.hcSave,
  1750.       NewItem  ('Save ~D~one',         '^KD',  Drivers.kbNoKey,    NewEdit.cmSaveDone,      CmdFile.hcSaveDone,
  1751.       NewItem  ('Save ~F~ile',         '^KF',  Drivers.kbNoKey,    NewEdit.cmSaveAs,        CmdFile.hcSaveAs,
  1752.  
  1753.       NewLine  (
  1754.  
  1755.       NewItem  ('C~h~ange Dir',           '',  Drivers.kbNoKey,    CmdFile.cmChangeDir,     CmdFile.hcChangeDir,
  1756.       NewItem  ('~S~hell To DOS',         '',  Drivers.kbNoKey,    CmdFile.cmShellToDos,    CmdFile.hcShellToDos,
  1757.  
  1758.       NewLine  (
  1759.  
  1760.       NewItem  ('~E~xit',            'Alt-X',  Drivers.kbAltX,     Views.cmQuit,            CmdFile.hcExit,
  1761.  
  1762.     nil)))))))))))),
  1763.  
  1764.  
  1765.  
  1766.     { ---------------------------------------- }
  1767.     {                                          }
  1768.     { This is the EDIT submenu initialization. }
  1769.     {                                          }
  1770.     { ---------------------------------------- }
  1771.  
  1772.  
  1773.     NewSubMenu ('~E~dit', CmdFile.hcEdit_Menu, NewMenu (
  1774.  
  1775.       NewItem  ('~U~ndo',               '^U',  Drivers.kbNoKey,    Views.cmUndo,            CmdFile.hcUndo,
  1776.  
  1777.       NewLine  (
  1778.  
  1779.       NewItem  ('~C~lipboard',            '',  Drivers.kbNoKey,    CmdFile.cmClipboard,     CmdFile.hcClipboard,
  1780.       NewItem  ('C~o~py',         'Ctrl-Ins',  Drivers.kbCtrlIns,  Views.cmCopy,            CmdFile.hcCopy,
  1781.       NewItem  ('Cu~t~',         'Shift-Del',  Drivers.kbShiftDel, Views.cmCut,             CmdFile.hcCut,
  1782.       NewItem  ('~P~aste',       'Shift-Ins',  Drivers.kbShiftIns, Views.cmPaste,           CmdFile.hcPaste,
  1783.  
  1784.       NewLine  (
  1785.  
  1786.       NewItem  ('C~l~ear',        'Ctrl-Del',  Drivers.kbCtrlDel,  Views.cmClear,           CmdFile.hcClear,
  1787.  
  1788.     nil))))))))),
  1789.  
  1790.  
  1791.  
  1792.     { ------------------------------------------ }
  1793.     {                                            }
  1794.     { This is the SEARCH submenu initialization. }
  1795.     {                                            }
  1796.     { ------------------------------------------ }
  1797.  
  1798.  
  1799.     NewSubMenu ('~S~earch', CmdFile.hcSearch_Menu, NewMenu (
  1800.  
  1801.       NewItem  ('~F~ind',              '^QF',  Drivers.kbNoKey,    NewEdit.cmFind,          CmdFile.hcFind,
  1802.       NewItem  ('~S~earch/Replace',    '^QA',  Drivers.kbNoKey,    NewEdit.cmReplace,       CmdFile.hcReplace,
  1803.  
  1804.       NewLine  (
  1805.  
  1806.       NewItem  ('~A~gain',              '^L',  Drivers.kbNoKey,    NewEdit.cmSearchAgain,   CmdFile.hcAgain,
  1807.  
  1808.     nil))))),
  1809.  
  1810.  
  1811.  
  1812.     { ----------------------------------------- }
  1813.     {                                           }
  1814.     { This is the WINDOW submenu initalization. }
  1815.     {                                           }
  1816.     { ----------------------------------------- }
  1817.  
  1818.  
  1819.     NewSubMenu ('~W~indows', CmdFile.hcWindows_Menu,   NewMenu (
  1820.  
  1821.       NewItem  ('~R~esize/Move',   'Ctrl-F5',  Drivers.kbCtrlF5,  Views.cmResize,          CmdFile.hcResize,
  1822.       NewItem  ('~Z~oom',               'F5',  Drivers.kbF5,      Views.cmZoom,            CmdFile.hcZoom,
  1823.       NewItem  ('~P~revious',     'Shift-F6',  Drivers.kbShiftF6, Views.cmPrev,            CmdFile.hcPrev,
  1824.       NewItem  ('~N~ext',               'F6',  Drivers.kbF6,      Views.cmNext,            CmdFile.hcNext,
  1825.       NewItem  ('~C~lose',          'Alt-F3',  Drivers.kbAltF3,   Views.cmClose,           CmdFile.hcClose,
  1826.       NewItem  ('~T~ile',                 '',  Drivers.kbNoKey,   Views.cmTile,            CmdFile.hcTile,
  1827.       NewItem  ('C~a~scade',              '',  Drivers.kbNoKey,   Views.cmCascade,         CmdFile.hcCascade,
  1828.  
  1829.     nil)))))))),
  1830.  
  1831.  
  1832.  
  1833.     { ------------------------------------------ }
  1834.     {                                            }
  1835.     { This is the DESKTOP submenu initalization. }
  1836.     {                                            }
  1837.     { ------------------------------------------ }
  1838.  
  1839.  
  1840.     NewSubMenu ('~D~esktop', CmdFile.hcDesktop_Menu,  NewMenu (
  1841.  
  1842.       NewItem  ('~L~oad Desktop',         '',  Drivers.kbNoKey,   CmdFile.cmLoadDesktop,       CmdFile.hcLoadDesktop,
  1843.       NewItem  ('~S~ave Desktop',         '',  Drivers.kbNoKey,   CmdFile.cmSaveDesktop,       CmdFile.hcSaveDesktop,
  1844.  
  1845.       NewLine  (
  1846.  
  1847.       NewItem  ('~4~3/50 Lines',          '',  Drivers.kbNoKey,   CmdFile.cmToggleVideo,       CmdFile.hcToggleVideo,
  1848.  
  1849.     nil))))),
  1850.  
  1851.   nil))))))));
  1852.  
  1853.  
  1854. end; { T_EditDemo.InitMenuBar }
  1855.  
  1856.  
  1857.  
  1858. { ---------------------------------------------------------------------------}
  1859.  
  1860.  
  1861.  
  1862. procedure T_EditDemo.InitStatusLine;
  1863.  
  1864.  
  1865.   { ------------------------------------------------------- }
  1866.   {                                                         }
  1867.   { This procedure sets up the status line and its options. }
  1868.   {                                                         }
  1869.   { ------------------------------------------------------- }
  1870.  
  1871.  
  1872. VAR
  1873.  
  1874.   R : TRect;  { Bounds of the desktop. }
  1875.  
  1876.  
  1877. begin
  1878.  
  1879.  
  1880.  
  1881.   { --------------------------------------------------------- }
  1882.   {                                                           }
  1883.   { Get the extent of the desktop and pull up bottom line -1. }
  1884.   {                                                           }
  1885.   { --------------------------------------------------------- }
  1886.  
  1887.  
  1888.   GetExtent (R);
  1889.   R.A.Y := R.B.Y - 1;
  1890.  
  1891.  
  1892.  
  1893.   { ------------------------------------------------------------------------- }
  1894.   {                                                                           }
  1895.   { This is the Statusline initialization.                                    }
  1896.   { The format for declaring a NewStatusKey in a NewStatusDef is:             }
  1897.   {                                                                           }
  1898.   { Name and Keys - a string, surrounding key select characters with tilde's. }
  1899.   { Key Command   - TurboVision "kb????" command to bind as hot key.          }
  1900.   { Item Command  - TurboVision "cm????" commnad to bind to item.             }
  1901.   {                                                                           }
  1902.   { ------------------------------------------------------------------------- }
  1903.  
  1904.  
  1905.   StatusLine := New (P_Status_Line_Help, Init (R,
  1906.  
  1907.      NewStatusDef (Views.hcDragging, Views.hcDragging,
  1908.  
  1909.        NewStatusKey ('',                        Drivers.kbF1,       Views.cmHelp,
  1910.        NewStatusKey ('~' + #24 + #25
  1911.                          + #26 + #27
  1912.                          + '~:Move,',           Drivers.kbNoKey,    Views.cmValid,
  1913.        NewStatusKey ('~Shift-' + #24
  1914.                          + #25 + #26
  1915.                          + #27 + '~:Resize,',   Drivers.kbNoKey,    Views.cmValid,
  1916.        NewStatusKey ('~Enter~:Done,',           Drivers.kbNoKey,    Views.cmValid,
  1917.        NewStatusKey ('~Esc~:Cancel',            Drivers.kbNoKey,    Views.cmValid,
  1918.  
  1919.     nil))))),
  1920.  
  1921.     NewStatusDef   (0, CmdFile.hcExtra_Menu,
  1922.  
  1923.       NewStatusKey ( '~F1~:Help,',              Drivers.kbF1,       Views.cmHelp,
  1924.       NewStatusKey ( '~F2~:Save,',              Drivers.kbF2,       NewEdit.cmSave,
  1925.       NewStatusKey ( '~F3~:Open,',              Drivers.kbF3,       CmdFile.cmOpen,
  1926.       NewStatusKey ( '~F5~:Zoom,',              Drivers.kbF5,       Views.cmZoom,
  1927.       NewStatusKey ( '~F6~:Next,',              Drivers.kbF6,       Views.cmNext,
  1928.       NewStatusKey ( '~F10~:Menu',              Drivers.kbF10,      Views.cmMenu,
  1929.  
  1930.       NewStatusKey ('',                         Drivers.kbF1,       Views.cmHelp,
  1931.       NewStatusKey ('',                         Drivers.kbAltF3,    Views.cmClose,
  1932.       NewStatusKey ('',                         Drivers.kbF5,       Views.cmZoom,
  1933.       NewStatusKey ('',                         Drivers.kbF6,       Views.cmNext,
  1934.       NewStatusKey ('',                         Drivers.kbShiftF6,  Views.cmPrev,
  1935.       NewStatusKey ('',                         Drivers.kbCtrlF5,   Views.cmResize,
  1936.       NewStatusKey ('',                         Drivers.kbF10,      Views.cmMenu,
  1937.       NewStatusKey ('',                         Drivers.kbAltX,     Views.cmQuit,
  1938.  
  1939.     nil)))))))))))))),
  1940.  
  1941.     NewStatusDef   (CmdFile.hcExtra_Menu, CmdFile.hcMisc_Commands,
  1942.  
  1943.       NewStatusKey ('~F1~:Help',                Drivers.kbF1,       Views.cmHelp,
  1944.  
  1945.     nil),
  1946.  
  1947.     NewStatusDef   (CmdFile.hckbShift, CmdFile.hckbShift,
  1948.  
  1949.       NewStatusKey ( '~Del~:Cut,',              Drivers.kbShiftDel, Views.cmCut,
  1950.       NewStatusKey ( '~F6~:Prev,',              Drivers.kbShiftF6,  Views.cmPrev,
  1951.       NewStatusKey ('~Ins~:Paste',              Drivers.kbShiftIns, Views.cmPaste,
  1952.  
  1953.     nil))),
  1954.  
  1955.     NewStatusDef   (CmdFile.hckbCtrl, CmdFile.hckbCtrl,
  1956.  
  1957.       NewStatusKey ('~B~:Reformat,',            Drivers.kbNoKey,    NewEdit.cmReformPara,
  1958.       NewStatusKey ( '~Del~:Clear,',            Drivers.kbCtrlDel,  Views.cmClear,
  1959.       NewStatusKey ( '~F5~:Resize,',            Drivers.kbCtrlF5,   Views.cmResize,
  1960.       NewStatusKey (  '~Ins~:Copy,',            Drivers.kbCtrlIns,  Views.cmCopy,
  1961.       NewStatusKey (     '~U~:Undo',            Drivers.kbNoKey,    Views.cmUndo,
  1962.  
  1963.     nil))))),
  1964.  
  1965.     NewStatusDef   (CmdFile.hckbAlt, CmdFile.hckbAlt,
  1966.  
  1967.       NewStatusKey ('~F3~:Close,',              Drivers.kbAltF3,    Views.cmClose,
  1968.       NewStatusKey (   '~X~:Exit',              Drivers.kbAltX,     Views.cmQuit,
  1969.  
  1970.     nil)),
  1971.  
  1972.     NewStatusDef   (CmdFile.hcEditor_Commands, $FFFE,
  1973.  
  1974.       NewStatusKey ( '~F1~:Help,',              Drivers.kbF1,       Views.cmHelp,
  1975.       NewStatusKey ( '~F2~:Save,',              Drivers.kbF2,       NewEdit.cmSave,
  1976.       NewStatusKey ( '~F3~:Open,',              Drivers.kbF3,       CmdFile.cmOpen,
  1977.       NewStatusKey ( '~F5~:Zoom,',              Drivers.kbF5,       Views.cmZoom,
  1978.       NewStatusKey ( '~F6~:Next,',              Drivers.kbF6,       Views.cmNext,
  1979.       NewStatusKey ( '~F10~:Menu',              Drivers.kbF10,      Views.cmMenu,
  1980.  
  1981.       NewStatusKey ('',                         Drivers.kbF1,       Views.cmHelp,
  1982.       NewStatusKey ('',                         Drivers.kbAltF3,    Views.cmClose,
  1983.       NewStatusKey ('',                         Drivers.kbF5,       Views.cmZoom,
  1984.       NewStatusKey ('',                         Drivers.kbF6,       Views.cmNext,
  1985.       NewStatusKey ('',                         Drivers.kbShiftF6,  Views.cmPrev,
  1986.       NewStatusKey ('',                         Drivers.kbCtrlF5,   Views.cmResize,
  1987.       NewStatusKey ('',                         Drivers.kbF10,      Views.cmMenu,
  1988.       NewStatusKey ('',                         Drivers.kbAltX,     Views.cmQuit,
  1989.  
  1990.     nil)))))))))))))),
  1991.  
  1992.     NewStatusDef   ($FFFF, $FFFF,
  1993.  
  1994.       NewStatusKey ('~Enter~:Select,',          Drivers.kbNoKey,    Views.cmValid,
  1995.       NewStatusKey ('~Esc~:Exit,',              Drivers.kbEsc,      Views.cmClose,
  1996.       NewStatusKey ('~F5~:Zoom,',               Drivers.kbF5,       Views.cmZoom,
  1997.       NewStatusKey ('~Shift-Tab~:Prev,',        Drivers.kbNoKey,    Views.cmValid,
  1998.       NewStatusKey ('~Tab~:Next',               Drivers.kbNoKey,    Views.cmValid,
  1999.       NewStatusKey ('',                         Drivers.kbAltF3,    Views.cmClose,
  2000.       NewStatusKey ('',                         Drivers.kbF5,       Views.cmZoom,
  2001.       NewStatusKey ('',                         Drivers.kbCtrlF5,   Views.cmResize,
  2002.  
  2003.     nil)))))))),
  2004.  
  2005.   nil))))))))));
  2006.  
  2007.  
  2008. end; { T_EditDemo.InitStatusLine }
  2009.  
  2010.  
  2011.  
  2012. { ---------------------------------------------------------------------------}
  2013.  
  2014.  
  2015.  
  2016. { MEMWIN - Start. }
  2017.  
  2018. function T_EditDemo.Insert_Memory_Indicator : Boolean;
  2019.  
  2020.  
  2021.   { -------------------------------------------------------------------- }
  2022.   {                                                                      }
  2023.   { This function installs the memory indicator view on the status line. }
  2024.   { A separate function was required because we need to dispose of it    }
  2025.   { and re-insert it whenever we toggle screen modes.                    }
  2026.   {                                                                      }
  2027.   { -------------------------------------------------------------------- }
  2028.  
  2029.  
  2030. VAR
  2031.  
  2032.   R : TRect;  { Object to show rectangle bounds.  }
  2033.  
  2034. begin
  2035.  
  2036.   GetExtent (R);
  2037.   Dec (R.B.X);
  2038.   R.A.X := R.B.X - 9;
  2039.   R.A.Y := R.B.Y - 1;
  2040.  
  2041.   Memory_Indicator := New (Gadgets.PHeapView, Init (R));
  2042.   Insert (Memory_Indicator);
  2043.  
  2044.  
  2045. end; { T_EditDemo.Insert_Memory_Indicator }
  2046.  
  2047. { MEMWIN - Stop. } { Function responsible for inserting heap view on status line. }
  2048.  
  2049.  
  2050.  
  2051. { ---------------------------------------------------------------------------}
  2052.  
  2053.  
  2054.  
  2055. { DESKTOP - Start. }
  2056.  
  2057. function  T_EditDemo.Load_Desktop : Boolean;
  2058.  
  2059.  
  2060.   { ---------------------------------------------------------------- }
  2061.   {                                                                  }
  2062.   { Since the safety pool is only large enough to guarantee that     }
  2063.   { allocating a window will not run out of memory, loading the      }
  2064.   { entire desktop without checking LowMemory could cause a heap     }
  2065.   { error.  This means that each window should be read individually, }
  2066.   { instead of using Desktop's Load.                                 }
  2067.   {                                                                  }
  2068.   { ---------------------------------------------------------------- }
  2069.  
  2070.  
  2071. VAR
  2072.  
  2073.    S : PStream;
  2074.  
  2075. begin
  2076.  
  2077.   Load_Desktop := False;
  2078.  
  2079.   if Desktop_Name = '' then
  2080.     Exit;
  2081.  
  2082.   S := New (Objects.PBufStream, Init (Desktop_Name, Objects.stOpenRead, 1024));
  2083.  
  2084.  
  2085.  
  2086.   { ------------------------------------------------------------- }
  2087.   {                                                               }
  2088.   { If not enough memory, then tell user.  If the desktop file    }
  2089.   { does not exist, or could not be read, tell the user about it. }
  2090.   {                                                               }
  2091.   { ------------------------------------------------------------- }
  2092.  
  2093.  
  2094.   if Memory.LowMemory then
  2095.     App.Application^.OutOfMemory
  2096.   else
  2097.     if S^.Status <> Objects.stOk then
  2098.       MsgBox.MessageBox (^C'Could not open desktop file ' + #13 + #13
  2099.                        + ^C + Desktop_Name, nil, MsgBox.mfOkButton + MsgBox.mfError)
  2100.     else
  2101.       begin
  2102.  
  2103.  
  2104.  
  2105.         { --------------------------------------------------------------- }
  2106.         {                                                                 }
  2107.         { Go read the desktop file and insert all views into the desktop. }
  2108.         { Tell the user if we encounter any sort of a problem.            }
  2109.         {                                                                 }
  2110.         { --------------------------------------------------------------- }
  2111.  
  2112.  
  2113.         DesktopReadViews (S^);
  2114.  
  2115.         if S^.Status <> Objects.stOk then
  2116.           MsgBox.MessageBox (^C'Error reading desktop file', nil,
  2117.                              MsgBox.mfOkButton + MsgBox.mfError)
  2118.         else
  2119.           Load_Desktop := True;
  2120.  
  2121.       end;
  2122.  
  2123.   Dispose (S, Done);
  2124.  
  2125.  
  2126. end; { T_EditDemo.Load_Desktop }
  2127.  
  2128. { DESKTOP - Stop. } { "Driver" code to load the desktop. }
  2129.  
  2130.  
  2131.  
  2132. { ------------------------------------------------------------------------ }
  2133.  
  2134.  
  2135.  
  2136. procedure T_EditDemo.OutOfMemory;
  2137.  
  2138.  
  2139.   { --------------------------------------------------------- }
  2140.   {                                                           }
  2141.   { This procedure is an overload method for the application. }
  2142.   { It brings up a message box stating "Not enough memory     }
  2143.   { available" whenever the user tries to open an application }
  2144.   { which can't fit into its place in the desktop.            }
  2145.   {                                                           }
  2146.   { --------------------------------------------------------- }
  2147.  
  2148.  
  2149. begin
  2150.  
  2151.   MsgBox.MessageBox (^C'Not enough memory available.',
  2152.     nil, MsgBox.mfError + Msgbox.mfOkButton);
  2153.  
  2154.  
  2155. end; { T_EditDemo.OutOfMemory }
  2156.  
  2157.  
  2158.  
  2159. { -------------------------------------------------------------------------- }
  2160.  
  2161.  
  2162.  
  2163. { DESKTOP - Start. }
  2164.  
  2165. function T_EditDemo.Save_Desktop : Boolean;
  2166.  
  2167.  
  2168.   { -------------------------------------------------------------- }
  2169.   {                                                                }
  2170.   { This function will save the current desktop to a file on disk. }
  2171.   {                                                                }
  2172.   { -------------------------------------------------------------- }
  2173.  
  2174.  
  2175. VAR
  2176.  
  2177.   S : Objects.PStream;
  2178.   F : File;
  2179.  
  2180. begin
  2181.  
  2182.   Save_Desktop := False;
  2183.  
  2184.   if Desktop_Name = '' then
  2185.     Exit;
  2186.  
  2187.   S := New (Objects.PBufStream, Init (Desktop_Name, Objects.stCreate, 1024));
  2188.  
  2189.  
  2190.  
  2191.   { ------------------------------------------------------------------ }
  2192.   {                                                                    }
  2193.   { If we have enough memory, and there's no problem with the stream   }
  2194.   { deallocate the editor clipboard, write all the desktop views to    }
  2195.   { desktop file on disk, and then reallocate the editor clipboard.    }
  2196.   { The clipboard MUST be deallocated and reallocated or the desktop   }
  2197.   { file will start filling with duplicate information with each save. }
  2198.   {                                                                    }
  2199.   { ------------------------------------------------------------------ }
  2200.  
  2201.  
  2202.   if not Memory.LowMemory and (S^.Status = Objects.stOk) then
  2203.     begin
  2204.  
  2205.       EditPkg.Deallocate_The_Clipboard;
  2206.  
  2207.       DesktopWriteViews (S^);
  2208.  
  2209.       EditPkg.Initialize_The_Clipboard;
  2210.  
  2211.  
  2212.  
  2213.       { ----------------------------------------------------------------- }
  2214.       {                                                                   }
  2215.       { Tell the user if there was any sort of error in writing the file. }
  2216.       {                                                                   }
  2217.       { ----------------------------------------------------------------- }
  2218.  
  2219.  
  2220.       if S^.Status <> Objects.stOk then
  2221.         begin
  2222.           MsgBox.MessageBox (^C'Could not create ' + Desktop_Name, nil,
  2223.                              MsgBox.mfOkButton + MsgBox.mfError);
  2224.           Dispose (S, Done);
  2225.           Assign (F, Desktop_Name);
  2226.           Erase (F);
  2227.           Exit;
  2228.         end;
  2229.     end;
  2230.  
  2231.   Dispose (S, Done);
  2232.   Save_Desktop := True;
  2233.  
  2234.  
  2235. end; { T_EditDemo.Save_Desktop }
  2236.  
  2237. { DESKTOP - Stop. } { "Driver" code to store the desktop. }
  2238.  
  2239.  
  2240.  
  2241. { ------------------------------------------------------------------------ }
  2242.  
  2243.  
  2244.  
  2245. { SCRNSZ - Start. }
  2246.  
  2247. procedure T_EditDemo.Toggle_Video_Mode;
  2248.  
  2249.  
  2250.   { --------------------------------------------------------------------- }
  2251.   {                                                                       }
  2252.   { This procedure toggles the video mode between normal and 43/50 lines. }
  2253.   { Each time the video mode is toggled, the memory indicator view must   }
  2254.   { be deallocated and re-inserted into the desktop.  Failure to do so    }
  2255.   { will result in the memory indicator view showing up in the middle of  }
  2256.   { the screen in 43/50 line mode -- not pretty!                          }
  2257.   {                                                                       }
  2258.   { --------------------------------------------------------------------- }
  2259.  
  2260.  
  2261. begin
  2262.  
  2263.   if Drivers.HiresScreen = True then
  2264.     begin
  2265.  
  2266.       if Memory_Indicator <> nil then
  2267.         Dispose (Memory_Indicator, Done);
  2268.  
  2269.       App.TApplication.SetScreenMode (Drivers.ScreenMode XOR Drivers.smFont8x8);
  2270.       Current_Screen_Mode := Drivers.ScreenMode;
  2271.  
  2272.       Insert_Memory_Indicator;
  2273.  
  2274.     end;
  2275.  
  2276.  
  2277. end; { T_EditDemo.Toggle_Video_Mode }
  2278.  
  2279. { SCRNSZ - Stop. } { Procedure responsible for toggling normal and 43/50 line mode. }
  2280.  
  2281.  
  2282.  
  2283. { ---------------------------------------------------------------------------}
  2284. {                                                                            }
  2285. {                               MAIN PROCEDURE                               }
  2286. {                                                                            }
  2287. { ---------------------------------------------------------------------------}
  2288.  
  2289.  
  2290. VAR
  2291.  
  2292.   Demo_Application : T_EditDemo;         { The demo program desktop. }
  2293.  
  2294.  
  2295. begin
  2296.  
  2297.   Demo_Application.Init;                 { Initialize the system.    }
  2298.   Demo_Application.Run;                  { Run the system.           }
  2299.   Demo_Application.Done;                 { Deallocate the system.    }
  2300.  
  2301.   writeln ('End program.');
  2302.  
  2303.  
  2304. end. { Program EditDemo }
  2305.